﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebCoreAPI.DDDMediatR;
using WebCoreAPI.Filter;
using WebCoreAPI.Models;

namespace WebCoreAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MediatRController : ControllerBase
    {
        private readonly IMediator mediator;

        public MediatRController(IMediator mediator) 
        {
            this.mediator= mediator;
        }
        [UnCheckJW]
        [HttpPost]
        public async Task<IActionResult> Login(LoginRequest req)
        {
            //publish可以有多个订阅者
            await mediator.Publish(new MediatRContent(req.UseName));
            //await mediator.Send(req); //只能有一个接收者，一般不使用
            return Ok("ok");
        }
    }
}
